<?php
include_once(dirname(__FILE__).'/../domain/Booking.php');
include_once(dirname(__FILE__).'/../database/dbBookings.php');
include_once(dirname(__FILE__).'/../domain/Loaner.php');
include_once(dirname(__FILE__).'/../database/dbLoaners.php');
class testdbBookings extends UnitTestCase {
    function testdbBookingsModule() {
        
        // create a booking and test inserting and retrieving it from dbBookings
        $b = new Booking("11-02-07","Meghan2077291234","Tiny",
                  array("Meghan:mother", "Jean:father", "Teeny:sibling"),
                  array(),
                  "Millie2073631234","Maine Med");
        $this->assertTrue(insert_dbBookings($b));
        $this->assertTrue(retrieve_dbBookings($b->get_id()));
        
        //checks that the initial status is "pending"
        $this->assertTrue(retrieve_dbBookings($b->get_id())->get_status(), "pending");
        
        // make some changes and test updating it in the database
        // Add a loaner to the booking
		$b->add_loaner("remote3");
		$b->add_occupant("Jordan","brother");
        $this->assertTrue($b->assign_room("126"));
        $bretrieved = retrieve_dbBookings($b->get_id());
        $this->assertTrue(in_array("Jordan:brother", $bretrieved->get_occupants()));
        $this->assertTrue(in_array("remote3", $bretrieved->get_loaners()));
        $this->assertEqual($bretrieved->get_status(),"active");
        $this->assertEqual($bretrieved->get_id(), $b->get_id());
        $this->assertEqual($bretrieved->get_room_no(), "126");
        
        //tests updating after a checkout
        $this->assertTrue($b->check_out("11-03-06"));
        $bretrieved2 = retrieve_dbBookings($b->get_id());
        $this->assertEqual($bretrieved2->get_status(), "closed");
        $this->assertEqual($bretrieved2->get_date_out(),"11-03-06");
        
        //tests the delete function
        $this->assertTrue(delete_dbBookings($b->get_id()));
        $this->assertFalse(retrieve_dbBookings($b->get_id()));
                 
        echo ("testdbBookings complete");
    }
}

?>

